package capaDominio;
import java.io.IOException;
import java.io.StringReader;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

/**
 * 
 */

/**
 * @author AJ
 *
 */
public class utilsXML {
	
	public static Document getXML(String msj) {
		try {
		    SAXBuilder builder = new SAXBuilder();
	        builder.setValidation(true);
		    Document xml = builder.build(new StringReader(msj));
		    
		    return xml;
		    
		} 
		catch(JDOMException e) {
			//e.printStackTrace();
			System.out.println("Error JDOM!: XML Incorrecto");
		}
		catch(IOException e) {
			e.printStackTrace();
			System.out.println("Error IO!");
		}
		
		return null;
	}
	
	public static String getXML_type(Document xml) {
	    Element mensaje = xml.getRootElement();
	    Element content = (Element)mensaje.getChildren().get(0);
	    
	    return content.getName();
	}
}

